<template>
  <div class="app-container">
    <div class="dashboard-editor-container">
      <el-row>
        <el-col :xs="24" :sm="24" :lg="24"
                style="padding-left:16px;padding-right: 16px;">
          <el-card class="cardbox1" :style="{background:$store.getters.theme}">
            <div class="cbox1">
              <p class="p1">认证中心简介</p>
              <p class="p2">实现登录认证的统一管理，提供多种认证方式，账号密码、动态口令等，支持账号解锁，提供三方应用的单点登录登出配置，支持CAS、OAUTH2、RestAPI等方式集成；为外部应用提供认证、单点集成的API；支持租户间数据隔离，租户也可设置自己的登录认证策略；记录认证日志信息，便于后期追踪。</p>
            </div>
            <div class="cbox2">
              <el-image :src="require('@/framework/assets/welcomePicture.png')" fit="fill" />
            </div>
          </el-card>
        </el-col>
      </el-row>
      <el-row>
        <el-col :xs="24" :sm="24" :lg="24"
                style="padding-left:16px;padding-right: 16px;margin-bottom: 16px;">
          <el-card style="margin-top:16px">
            <p class="title">数据统计分析</p>
            <PanelGroup @handleSetLineChartData="handleSetLineChartData" />
            <div class="titleTime">
              <p class="title">认证情况</p>
              <div style="display: flex; justify-content: flex-end;">
                <el-radio-group v-model="editableTabsValue" @change="getTime">
                  <el-radio-button
                    v-for="(item,index) in editableTabs"
                    :key="index"
                    :value="item.value"
                    :label="item.value"
                  >{{ item.label }}</el-radio-button>
                </el-radio-group>
                <el-date-picker
                  v-model="allDate"
                  style="margin-left: 12px;"
                  type="daterange"
                  value-format="yyyy-MM-dd"
                  range-separator="至"
                  start-placeholder="开始日期"
                  end-placeholder="结束日期"
                  :picker-options="setDateRange"
                  @change="changeTime"
                />
              </div>
            </div>

            <auth-Situation-Bar-Chart ref="barChartRef" />
          </el-card>
        </el-col>
      </el-row>
    </div>
  </div>

</template>

<script>
import PanelGroup from './component/PanelGroup.vue'
import authSituationBarChart from './component/authSituationBarChart.vue'

export default {
  name: 'AuthOverview',
  components: {
    PanelGroup,
    authSituationBarChart
  },
  data() {
    return {
      editableTabsValue: 7,
      editableTabs: [
        {
          label: '近七天',
          value: 7
        },
        {
          label: '近一个月',
          value: 30
        },
        {
          label: '近三个月',
          value: 90
        }
      ],
      tabIndex: 2,
      allDate: [],
      setDateRange: {
        disabledDate: (time) => {
          // 只能选择当前 1 年内的时间
          const year = 365 * 24 * 3600 * 1000
          // 注意：这是从当前日期开始往前算,往后的日期不可选
          return time.getTime() > Date.now() || time.getTime() < (Date.now()) - year
        }
      }
    }
  },
  created() {
    this.$nextTick(() => {
      this.getTime(this.editableTabsValue)
    })
  },
  methods: {
    handleSetLineChartData(type) {
      // this.lineChartData = lineChartData[type]
    },
    changeTime(val) {
      if (!val) {
        this.allDate = []
        this.getTime(this.editableTabsValue)
      } else {
        this.editableTabsValue = null
        this.allDate = val
        this.beginTime = this.allDate[0]
        this.endTime = this.allDate[1]
        this.$refs.barChartRef.initChart(this.beginTime, this.endTime)
      }
    },
    getTime(n) {
      this.allDate = []
      const num = parseInt((n - 1) * 24 * 3600 * 1000)
      const days = new Date()
      const end = `${days.getFullYear()}-${days.getMonth() + 1}-${days.getDate()}`
      const dayend = new Date()
      dayend.setTime(dayend.getTime() - num)
      const start = `${dayend.getFullYear()}-${dayend.getMonth() + 1}-${dayend.getDate()}`
      this.changeDate = [start, end]
      if (this.changeDate) {
        this.beginTime = this.changeDate[0]
        this.endTime = this.changeDate[1]
      }
      this.$refs.barChartRef.initChart(this.beginTime, this.endTime)
    }

  }
}
</script>

<style lang="scss" scoped>
.el-footer{
  border-top: 1px solid #DCDFE6 !important;
}
.titleTime{
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-top: 16px;
}
.title{
  margin:0 0 16px;
  font-weight: 500;
  color: #131414;
  line-height: 24px;
}
 .cardbox1{
    margin-top: 16px;
    // height: 312px;
      position: relative;
    .el-card__body{
      display: flex;
      // padding: 20px!important;
      .cbox1{
        width: 70%;
        margin-left: 20px;
        z-index: 2;
      }
      .cbox2{
        position: absolute;
        bottom: 20px;
        right: 20px;
        z-index: 1;
        margin-left: 20px;
      }
      p{
        font-size: 18px;
        font-family: HarmonyOS Sans SC-Medium, HarmonyOS Sans SC;
        font-weight: 500;
        color: #FFFFFF;
        line-height: 24px;
      }
      .p2{
        font-size: 16px;
        // line-height: 22px;
        // margin: 24px 0 ;
      }
    }
  }
</style>
